package cn.klaw.flowable.model.util;

import cn.klaw.flowable.model.task.FlowModel;

import java.util.ArrayList;
import java.util.List;

/**
 * 事件
 *
 *
 * @version 5.0.x
 * @since 2024/8/21 15:31
 */
public class FlowEventHolder {

    private static final ThreadLocal<List<EventModel>> EVENT_LIST = new ThreadLocal<>();

    public static void addEvent(Integer status, FlowModel flowModel) {
        EventModel eventModel = new EventModel();
        eventModel.setStatus(status);
        eventModel.setFlowModel(flowModel);
        List<EventModel> list = EVENT_LIST.get() != null ? EVENT_LIST.get() : new ArrayList<>();
        list.add(eventModel);
        EVENT_LIST.set(list);
    }

    public static List<EventModel> getAllEvent() {
        return EVENT_LIST.get() != null ? EVENT_LIST.get() : new ArrayList<>();
    }

    public static void clear() {
        EVENT_LIST.remove();
    }
}
